/*
 * Copyright 2014-2017 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.project.bootstrap;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.project.business.BusinessConfiguration;
import com.example.project.business.aop_demo.Calculator;
import com.example.project.business.aop_demo.SomeService;

@SpringBootApplication(scanBasePackageClasses = {BusinessConfiguration.class})
public class SampleJUnit5Application {

	public static void main(String[] args) {
		ConfigurableApplicationContext run = new SpringApplication(SampleJUnit5Application.class).run();
		AnnotationConfigServletWebServerApplicationContext xxx = (AnnotationConfigServletWebServerApplicationContext) run;
		// AnnotationConfigServletWebServerApplicationContext		
		System.out.println("---------- WebApplicationContext " + xxx);
		
		//	org.springframework.boot.web.embedded.tomcat.TomcatWebServer   +  	 org.apache.catalina.core.ApplicationContextFacade
		System.out.println("---------- Web Context " +xxx.getWebServer() + " ----> servlet Context " +xxx.getServletContext());

		//		@Component , @Bean , xml, BFPP.register 
//		Bean声明的第5种方式
		xxx.registerBean(Calculator.class);
		
		SomeService bean = run.getBean(SomeService.class);
		System.out.println(bean);
		System.out.println(run.getBean(Calculator.class));
		
		bean.printAsync();
//		bean.print();
		bean.printTransaction();
	}

	@RestController
	private static class SampleController {

		@RequestMapping("/")
		public String index() {
			return "Hello, World";
		}

	}

}
